﻿/* ================================================================================
<copyright file="frmAbout.cs" company="The Framework Factory, LLC" lastWriteTime="12/05/2012 23:23:47 PM">
  Copyright (c) 2012 The Framework Factory, LLC.  All rights reserved.
</copyright>
=================================================================================== */
using System;
using System.Reflection;
using System.Windows.Forms;

namespace FWF.Logging.Viewer
{
    /// <summary>
    /// 
    /// </summary>
    partial class frmAbout : Form
    {
        private readonly Assembly _assembly;

        /// <summary>
        /// Initializes a new instance of the <see cref="frmAbout" /> class.
        /// </summary>
        public frmAbout()
        {
            InitializeComponent();

            _assembly = Assembly.GetExecutingAssembly();

            Text = String.Format( "About {0} {0}", AssemblyTitle );
            lblProductName.Text = AssemblyProduct;
            lblVersion.Text = String.Format( "Version {0} {0}", AssemblyVersion );
            lblCopyright.Text = AssemblyCopyright;
            lblCompanyName.Text = AssemblyCompany;
            txtDescription.Text = AssemblyDescription;
        }

        /// <summary>
        /// Gets the assembly title.
        /// </summary>
        /// <value>
        /// The assembly title.
        /// </value>
        public string AssemblyTitle
        {
            get
            {
                object[] attributes = _assembly.GetCustomAttributes( typeof( AssemblyTitleAttribute ), false );
                if ( attributes.Length > 0 )
                {
                    var titleAttribute = (AssemblyTitleAttribute) attributes[ 0 ];
                    if ( titleAttribute.Title != "" )
                    {
                        return titleAttribute.Title;
                    }
                }
                return System.IO.Path.GetFileNameWithoutExtension( _assembly.CodeBase );
            }
        }

        /// <summary>
        /// Gets the assembly version.
        /// </summary>
        /// <value>
        /// The assembly version.
        /// </value>
        public string AssemblyVersion
        {
            get
            {
                return _assembly.GetName().Version.ToString();
            }
        }

        /// <summary>
        /// Gets the assembly description.
        /// </summary>
        /// <value>
        /// The assembly description.
        /// </value>
        public string AssemblyDescription
        {
            get
            {
                object[] attributes = _assembly.GetCustomAttributes( typeof( AssemblyDescriptionAttribute ), false );
                if ( attributes.Length == 0 )
                {
                    return string.Empty;
                }
                return ( (AssemblyDescriptionAttribute) attributes[ 0 ] ).Description;
            }
        }

        /// <summary>
        /// Gets the assembly product.
        /// </summary>
        /// <value>
        /// The assembly product.
        /// </value>
        public string AssemblyProduct
        {
            get
            {
                object[] attributes = _assembly.GetCustomAttributes( typeof( AssemblyProductAttribute ), false );
                if ( attributes.Length == 0 )
                {
                    return string.Empty;
                }
                return ( (AssemblyProductAttribute) attributes[ 0 ] ).Product;
            }
        }

        /// <summary>
        /// Gets the assembly copyright.
        /// </summary>
        /// <value>
        /// The assembly copyright.
        /// </value>
        public string AssemblyCopyright
        {
            get
            {
                object[] attributes = _assembly.GetCustomAttributes( typeof( AssemblyCopyrightAttribute ), false );
                if ( attributes.Length == 0 )
                {
                    return string.Empty;
                }
                return ( (AssemblyCopyrightAttribute) attributes[ 0 ] ).Copyright;
            }
        }

        /// <summary>
        /// Gets the assembly company.
        /// </summary>
        /// <value>
        /// The assembly company.
        /// </value>
        public string AssemblyCompany
        {
            get
            {
                object[] attributes = _assembly.GetCustomAttributes( typeof( AssemblyCompanyAttribute ), false );
                if ( attributes.Length == 0 )
                {
                    return string.Empty;
                }
                return ( (AssemblyCompanyAttribute) attributes[ 0 ] ).Company;
            }
        }

    }
}
